Overview
Thefetch_fundamental_data.py script retrieves detailed fundamental data including quarterly financial results, annual metrics, and valuation ratios for all stocks listed in master_isin_map.json. This is the second script in the EDL Pipeline.
Purpose
Fetches fundamental financial data including:- Quarterly results (Revenue, Net Profit, EPS, OPM)
- Historical quarterly comparisons (QoQ, YoY growth)
- Annual metrics (Sales Growth, EPS history)
- Ownership data (Promoter, FII, DII holdings)
- Valuation ratios (P/E, P/B, ROE, ROCE, D/E)
API Endpoint
https://open-web-scanx.dhan.co/scanx/fundamentalPOSTRequest timeout in seconds
Request Payload
Parameters
ISIN code of the security to fetch fundamental data for
The script batches ISINs into groups of 100 and sends them as an array:
Output Files
Consolidated fundamental data for all stocks (~35 MB). Each object contains:
isin- ISIN codeSymbol- Stock symbol (enriched from master map)Name- Company name (enriched from master map)quarterly_results- Array of quarterly financial dataannual_results- Annual financial metricsratios- Valuation and financial ratiosshareholding- Promoter, FII, DII holding percentages
Function Signature
Dependencies
requests- HTTP clientjson- JSON processingtime- Rate limiting delays
pipeline_utils.get_headers()- Returns standard API headers
master_isin_map.json- Generated byfetch_dhan_data.py
Code Example
Usage
Performance
- Execution Time: ~2-3 minutes for 2,775 stocks
- API Calls: ~28 requests (100 ISINs per batch)
- Output Size: ~35 MB
- Concurrency: Sequential with 0.5s delay between batches
- Batch Size: 100 ISINs per request
Notes
- Requires
master_isin_map.jsonto exist (runfetch_dhan_data.pyfirst) - Data is enriched with Symbol and Name for easier cross-referencing
- 30-second timeout per request to handle API delays
- 0.5-second delay between batches to avoid rate limiting